package com.tbit.uqbike.client.controller;

import com.tbit.uqbike.client.pojo.Result;
import com.tbit.uqbike.client.pojo.User;
import com.tbit.uqbike.client.pojo.vo.UserRidingScoreLogVO;
import com.tbit.uqbike.client.service.TokenService;
import com.tbit.uqbike.client.service.UserRidingScoreService;
import com.tbit.uqbike.client.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 用户骑行分
 *
 * @Author:BUGTian
 * @DATE: 2023/2/14
 */
@RestController
@RequestMapping("/userRidingScore")
public class UserRidingScoreController {

    @Autowired
    private TokenService tokenService;
    @Autowired
    private UserService userService;
    @Autowired
    private UserRidingScoreService userRidingScoreService;

    /**
     * 获取用户骑行分
     *
     * @param token
     * @return
     */
    @GetMapping("/getUserRidingScore")
    public Result<Integer> getUserRidingScore(String token) {
        User user = tokenService.getUser(token);
        return Result.success(userService.getUserRidingScore(user.getUserId()));
    }

    /**
     * 获取用户骑行分变更日志
     *
     * @param token
     * @param getAll true：获取全部 ，不传默认获取前30个
     * @return
     */
    @GetMapping("/getUserRidingScoreLog")
    public Result<List<UserRidingScoreLogVO>> getUserRidingScoreLog(String token, Boolean getAll) {
        User user = tokenService.getUser(token);
        if (getAll == null) {
            getAll = false;
        }
        List<UserRidingScoreLogVO> logs = userRidingScoreService.getUserRidingScoreLog(user.getUserId(), getAll);
        return Result.success(logs);
    }


}
